<?php 
/*********************************************************
This file provides a list of available MO batches to send
to the bank blinded
*********************************************************/

/*********************************************************
includes
*********************************************************/
require_once 'config.inc';
require_once '_common.inc';
require_once '_customer.inc';
require_once '_db.inc';
require_once '_rsa.inc';
require_once '_ui.inc';

/*********************************************************
set the correct time zone to eliminate warnings in debug
date_default_timezone_set('America/New_York');

$script_tz = date_default_timezone_get();

if (strcmp($script_tz, ini_get('date.timezone'))){
    echo 'Script timezone differs from ini-set timezone.';
}

*********************************************************/

$us_id_str = $_POST["us_id"];

$us_id = explode(":",$us_id_str);

$us = $us_id[0];

for($i = 1; $i < sizeof($us_id); $i++)
	$id_string[($i-1)] = $us_id[$i]; 

?>
<HTML>

<HEAD>
	<title>Accept Money Order</title>
</HEAD>



<?php
ui_print_header('Merchant - Accept Money Order');

echo "Customer is marking money order as spent...<BR><BR>";

$conn = db_connect(CUSTOMER_DB_USER, CUSTOMER_DB_PASSWORD);
$sql = "update mo_detail_customer set spent = 1 where uniqueness_string = '" . $us ."'";
$stmt = oci_parse($conn, $sql);
oci_execute($stmt);
oci_close($conn);
	
echo "Saving ID Strings to merchant's database...<BR><BR>";
	
/*********************************************************
connect to db
*********************************************************/
$conn = db_connect(MERCHANT_DB_USER, MERCHANT_DB_PASSWORD);

/*********************************************************
get available mo batches for merchant
*********************************************************/

for($i = 0; $i < sizeof($id_string); $i++){

$sql = "insert into mo_idstrings_merchant(uniqueness_string, idstring_n, id_string)
		values( '" . $us . "', " . $i . ", '" . $id_string[$i] . "')"; 

$stmt = oci_parse($conn, $sql);
oci_execute($stmt);
}

$sql = "update mo_detail_merchant set verified = 1 where uniqueness_string = '" . $us ."'";

$stmt = oci_parse($conn, $sql);
oci_execute($stmt);
/*********************************************************
close db connection
*********************************************************/
oci_close($conn);



echo "<BR><b><i>MONEY ORDER ACCEPTED!</i></b><BR><BR>";
?>
<BR>
<form action="./6.php">
<input type="submit" value="Go to the Bank as the Merchant">
</form>
<br>
<?php ui_print_footer(date('Y-m-d H:i:s'));
?>

</BODY></HTML>